package com.fth.learn.chapter05;

import java.util.Arrays;

/**
 * 随堂测试练习处
 * YiMi
 *
 * @author YiMi
 * @version 1.0
 * @date 2023/7/12 15:55
 */

public class LearnArray04 {
    public static void question1(){
        int[] as={1,2,3,4,5,6,7};
        int[] ints = Arrays.copyOfRange(as,2, 5);
        System.out.println(Arrays.toString(ints));
    }

    public static void question2(){
        int[] arr={1,1,1,2,3,3,4,2,2,4,5,5,1,2,3};
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));

        for (int i = 0; i < arr.length; i++) {
            if(arr[i]>5){
                System.out.println("数组里面的全部元素只能为1-5的数");
                break;
            }
            int num = 0;
            for (int j = i; j < arr.length; j++) {
                if(arr[i] != arr[j]){
                    num=j;
                    break;
                }
            }
            System.out.printf("当前数组里的%d,有%d个\n", arr[i], num == 0 ? arr.length - i : num - i);
                i = (num == 0) ? arr.length - 1 : num - 1;
        }
    }


    public static void question3(){

        int[][] arr = {{1,2,3},{4,5,6},{7,8,9}};
        int num=0,num1=0;
        for (int i = 0; i < 3; i++) {
            num=arr[i][i]+num;
        }
        System.out.println(num);

        int rows = arr.length;
        int columns = arr[0].length;
        for (int i = 0; i < rows; i++) {
            num1=arr[i][columns-i-1]+num1;
        }
        System.out.println(num1);
    }




        public static void main(String[] args) {
            question1();
            question2();
            question3();
    }
}
